@extends('admin.layouts.default')
@section('content')
    <div class="card">
    <div class="card-body">
        <ul class="nav nav-tabs nav-overflow bg-light rounded header-tabs ">
            <li class="nav-item">
                <a href="{{route('admin.user_role.index')}}" class="nav-link ml-2">用户-角色对照表</a>
            </li>
            <li class="nav-item">
                <a href="{{route('admin.user_role.store')}}" class="nav-link active">编辑用户角色</a>
            </li>
        </ul>
    </div>
        <div class="card-body">
        <form action="{{route('admin.user_role.update',$user_role)}}" method="post">
        @csrf @method('PUT')
            <h3>用户名: <span  class="badge badge-secondary">{{$user_role['name']}}</span></h3>
            <div class="row">
                @foreach($roles as $role)
                    <div class="col-3">
                        @if($user_role->hasRole($role))
                            <input type="checkbox" checked name="role[]" value="{{$role['name']}}">
                        @else
                            <input type="checkbox" name="role[]" value="{{$role['name']}}">
                        @endif
                        {{$role['title']}}
                    </div>
                @endforeach
            </div>
            @foreach($modules as $module)
                @if($module['permission'])
                    <div class="card">
                        <div class="card-header">
                            <h4 class="card-title">{{$module['name']}}</h4>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                @foreach($module['permission'] as $value)
                                    @if($user_role->can($value['name']))
                                        <input type="checkbox" checked disabled>
                                    @else
                                        <input type="checkbox" disabled>
                                    @endif
                                    <div class="col-3">
                                        {{$value['name']}}({{$value['title']}})
                                    </div>
                                @endforeach
                            </div>
                        </div>
                    </div>
                @endif
            @endforeach

        </div>
        <div class="card-footer text-muted">
            <button class="btn btn-sm btn-primary">提交修改</button>
        </div>
    </div>
    </form>
@endsection
